package com.shark.mq;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.io.IOException;
import java.text.SimpleDateFormat;

/**
 * @auther shark
 * @create 2024-08-13 0:02
 */
//@Component
@Slf4j
public class MyDelayMessageListener {

    public static final String EXCHANGE_DELAY = "exchange.delay.video";
    public static final String ROUTING_KEY_DELAY = "routing.key.delay.video";
    public static final String QUEUE_DELAY = "queue.delay.video";

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = QUEUE_DELAY, durable = "true", autoDelete = "false"),
            exchange = @Exchange(
                    value = EXCHANGE_DELAY,
                    durable = "true",
                    autoDelete = "false",
                    type = "x-delayed-message",
                    arguments = @Argument(name = "x-delayed-type", value = "direct")),
            key = {ROUTING_KEY_DELAY}
    ))
    public void process(String dataString, Message message, Channel channel) throws IOException
    {
        log.info("[生产者]" + dataString);
        log.info("[消费者]" + new SimpleDateFormat("hh:mm:ss").format(new Date()));
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
